linuxer_server_image = "linuxer/server:v4"
linuxer_server_name = "linuxer-server"

all: start_client

install: src_install

uninstall: src_uninstall

clean: src_clean tar_clean client_deb_clean

start_client: /opt/linuxer
	/opt/linuxer/bin/linuxer.bash

help:
	echo "TODO"

# source only
src_install: etc/* lib/* bin/* score doc
	test -d /opt/linuxer || mkdir -p /opt/linuxer >/dev/null 2>&1
	test -d /opt/linuxer/score || mkdir -p /opt/linuxer/score >/dev/null 2>&1
	cp -rf etc/ lib/ bin/ doc/ labs/ /opt/linuxer >/dev/null 2>&1
src_uninstall: /opt/linuxer
	rm -rf /opt/linuxer
src_clean:
	rm deb/opt -rf >/dev/null 2>&1

# tar.gz
linuxer.tar.gz: tar/
	test -d tar/linuxer || mkdir -p tar/linuxer >/dev/null 2>&1
	cp -rf etc/ bin/ doc/ labs/ lib/ score/ CHANGELOG LICENSE Makefile tar/linuxer
	>/dev/null 2>&1
	cd tar/ ; tar -cvzf ../linuxer.tar.gz linuxer/ >/dev/null 2>&1
tar_clean: 
	find . -name linuxer.tar.gz -exec rm -f '{}' >/dev/null 2>&1 \;
	rm -rf tar/linuxer >/dev/null 2>&1

# deb
client_deb_install:linuxer-client.deb
	dpkg -l linuxer-client >/dev/null 2>&1 || dpkg -i linuxer-client.deb
linuxer-client.deb:deb/
	test -d deb/opt && mkdir -p deb/opt/linuxer >/dev/null 2>&1
	cp -rf etc/ bin/ doc/ labs/ lib/ score/ CHANGELOG LICENSE deb/opt/linuxer
	>/dev/null 2>&1
	dpkg -b deb linuxer-client.deb
client_deb_clean:
	-rm -f linuxer-client.deb >/dev/null 2>&1
	-rm deb/opt -rf >/dev/null 2>&1
client_deb_uninstall:
	dpkg -l linuxer-client >/dev/null 2>&1 && dpkg -r linuxer-client

#image server
image_server: linuxer.tar.gz docker/Dockerfile
	cp linuxer.tar.gz docker/
	cd docker/; \
	docker build -t $(linuxer_server_image) .
	
#start server
start_server: stop_server
	docker run -d -p 8022:22 -p 8021:21 -p 8888:8888 --name $(linuxer_server_name) $(linuxer_server_image) entry.sh
#stop server
stop_server:
	docker rm -f $(linuxer_server_name) > /dev/null 2>&1
